package com.tgy.algorithm.base;

import java.util.Arrays;

public class RemoveDuplicateElement {
    public static int removeDuplicateElement(int[] arr) {

        if (null == arr) {
            return 0;
        }

        if (arr.length == 0 || arr.length == 1) {
            return arr.length;
        }
        // 0 0 1 1 2 2
        int slow = 0, fast = 1;
        while (fast < arr.length) {
            if(arr[slow] != arr[fast]) {
                arr[++slow] = arr[fast];
            }
            fast++;
        }
        return slow+1;
    }


    public static void main(String[] args) {

        int[] params = new int[]{0,0,1,1,2,2,4,5};
        int result = RemoveDuplicateElement.removeDuplicateElement(params);
        System.out.println(Arrays.toString(params));
        System.out.println(result);
    }
}
